<%@ page language="java" import="java.util.*"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
	<link rel="stylesheet" type="text/css" href="css/main.css">
	
   <style type="text/css">

	.content1 {
	
		width:99%;
		height:auto;
		margin:0;
		padding:0px 0px 0px 0px;
		border:5px solid #EEEEEE;
		
	}
	td {
	
	text-align : center;
	
	}
	
	
	</style>
  </head>
  
  <body>

     <div class="main">
    	<jsp:include page="head.jsp"/>
    
    	
    
    	<div class="content">
    		  
    		  <div class="content1">
    		  <h4>&lt;c:if&gt;</h4>

    		  <%
				  Random rand = new Random() ;
    		 %>

    		 <c:set var="num" scope="page">
    			<%= rand.nextInt(10) %>
    		 </c:set>
    		 
    		 <c:if test="${num == 9 }" var="result">
    		 	恭喜你中奖！
    		 </c:if>
    		 <c:if test="${not result }">
    		 	<c:out value="谢谢你的参与！${num }"/>
    		 </c:if>

    		  <br><hr>
    		  </div>
    		  
    		  
    		  
    		  <div class="content1">
    		  <h4>&lt;c:choose&gt;</h4>
    		   
    		   <c:choose>
    		   	  <c:when test="${num == 9 }">
    		   	  	恭喜你中了一等奖！
    		   	  </c:when>
    		   	  <c:when test="${num == 8 }">
    		   	     恭喜你中了二等奖！
    		   	  </c:when>
    		   	    <c:when test="${num == 7 }">
    		   	     恭喜你中了三等奖！
    		   	  </c:when>
    		   	  <c:otherwise>
    		   	  	谢谢你的参与！${num }
    		   	  	
    		   	  </c:otherwise>
    	
    		   
    		   </c:choose>
    		 
    		  <br><hr>
    		  </div>

    		  <div class="content1">
    		  	<h3>循环标签</h3>
    		  	<h4>&lt;c:forEach&gt;</h4>
    		  	 <%
    			 	Set<String> mySet = new HashSet<String>();
    			    
    			   
    			 	mySet.add("item1");  // alt + /
    			    mySet.add("item2");
    			    mySet.add("item3");
    			    mySet.add("item4");
    			    mySet.add("item5");
    			    session.setAttribute("mySet", mySet);
    			  
    			    
    			 %>
    			 该set中包含的数据是：<br>
    			 
    			 <table width="50%" align="center" border="1">
					 <tr>
						 <td> 行号</td>
						 <td>数据</td>
					 </tr>
    			 	<c:forEach var="item" items="${sessionScope.mySet }" varStatus="status">
    			 	    <c:if test="${status.index % 2 == 0 }" var="result">
    			 	    <tr bgcolor="#FFFFFF">
    			 	   
	    			 		<td>${status.count }</td>
	    			 		<td>${status.first? "":item }</td>
	    			 	</tr>
	    			 	</c:if>
	    			 	<c:if test="${!result }">
	    			    <tr bgcolor="#EEEEEE">
    			 	   
	    			 		<td>${status.count }</td>
	    			 		<td>${status.first? "":item }</td>
	    			 
	    			 	</tr>
	    			 	</c:if>
    			 	</c:forEach>
    			 
    			 
    			 </table>
    			 
    			 
    			<table width="50%" align="center" cellspacing="1" border="1">
    			<tr>
    				<td>行号</td>
    				<td>数据</td>
    			<tr>
    			<c:forEach var="item" items="${mySet}" varStatus="status">
    			<c:if var="result" test="${status.index %2 == 0}">
    			<tr bgcolor="#EEEEEE" >	
    				<td>${status.index }</td>
    				<td>${item }</td>
    				
    		
    			</tr>
    			</c:if>
    			<c:if test="${!result }">
    				<tr bgcolor="#FFFFFF">	
    				<td>${status.index }</td>
    				<td>${item }</td>
    			</tr>
    			</c:if>
    			</c:forEach>
    			</table>
    		<br><hr>

    		
    		 <h4>&lt;c:forToken&gt;</h4>
    		 <c:set var="sentence" value="JavaWeb:程序开发返范例宝典、典型模块大全；计算机学会通讯"/>
    		 <c:forTokens var="word" items="${sentence }" delims=":、；" varStatus="status">
    			<c:if test="${!status.last }" var="result">
    			<a href="#">${word }</a> &nbsp;|
    			</c:if>
    			<c:if test="${!result }">
    				<a href="#">${word }</a>
    			</c:if>
    		
    		 </c:forTokens>
    	
    		</div>
    		
        </div>
    		 
    		  
    		
    	<jsp:include page="copyright.jsp" />
    
    </div>
  </body>
</html>
